package com.ksyun.campus.metaserver.config;

import com.ksyun.campus.metaserver.interceptor.LeaderAwareInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web configuration
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Autowired
    private LeaderAwareInterceptor leaderAwareInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(leaderAwareInterceptor)
                .addPathPatterns("/api/v1/**")
                .excludePathPatterns(
                        "/api/v1/meta/getStatus",
                        "/api/v1/meta/listStatus", 
                        "/api/v1/meta/open",
                        "/api/v1/cluster/**",
                        "/api/v1/replica/**",
                        "/api/v1/admin/fsck/status"
                );
    }
}
